<template>
  <div>
    <div>
      <h1>获取指定书籍信息</h1>
      <input
        type="text"
        placeholder="请输入你要获取的书籍"
        v-model.trim="bookName"
      />
      <button @click="findFn">搜索</button>
    </div>
    <div>
      <h1>添加书籍</h1>
      <input
        type="text"
        placeholder="请输入书名"
        v-model.trim="bookObj.bookname"
      />
      <input
        type="text"
        placeholder="请输入出版社"
        v-model.trim="bookObj.publisher"
      />
      <input
        type="text"
        placeholder="请输入作者"
        v-model.trim="bookObj.author"
      />
      <button @click="addFn">添加书籍</button>
    </div>
  </div>
</template>

<script>
//引入
import axios from "axios";
//
axios.defaults.baseURL = "http://123.57.109.30:3006";
export default {
  data() {
    return {
      bookName: "",
      bookObj: {
        bookName: "",
        publisher: "",
        author: "",
      },
    };
  },
  methods: {
    //get方法
    findFn() {
      axios({
        url: "/api/getbooks",
        method: "get",
        params: {
          bookname: this.bookName,
        },
      })
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    addFn() {
      axios({
        url: "/api/addbook",
        method: "post",
        data: {
          ...this.bookObj,
          appkey: "7250d3eb-18e1-41bc-8bb2-11483665535a",
        },
      }).then((res) => {
        console.log(res);
      });
    },
  },
};
</script>

<style>
</style>